package com.android.kotlincoroutinemvvmdemo.contentprovider
import android.database.sqlite.SQLiteDatabase

object DBUpdateHelper {

    fun updateDB0(db: SQLiteDatabase?) {
        val tableGesture = StringBuilder().apply {
            append("create table if not exists ${SqlConstant.TABLE_GESTURE}")
            append(" (")
            append("${SqlConstant.TABLE_GESTURE_COLUMN_GESTURE_ID} integer primary key autoincrement,")
            append("${SqlConstant.TABLE_GESTURE_COLUMN_GESTURE_SWITCH} integer,")
            append("${SqlConstant.TABLE_GESTURE_COLUMN_GESTURE_RESULT} integer")
            append(")")
        }.toString()

        val tableStudent = StringBuilder().apply {
            append("create table if not exists ${SqlConstant.TABLE_STUDENT}")
            append(" (")
            append("${SqlConstant.TABLE_STUDENT_COLUMN_NUMBER_ID} integer primary key,")
            append("${SqlConstant.TABLE_STUDENT_COLUMN_NAME} varchar(32),")
            append("${SqlConstant.TABLE_STUDENT_COLUMN_GRADE} varchar(16),")
            append("${SqlConstant.TABLE_STUDENT_COLUMN_PHONE} varchar(32),")
            append("${SqlConstant.TABLE_STUDENT_COLUMN_HOBBY} varchar(256)")
            append(")")
        }.toString()

        db?.execSQL(tableGesture)
        db?.execSQL(tableStudent)
    }

    fun updateDB1(db: SQLiteDatabase?) {
        val sql =
            "alter table ${SqlConstant.TABLE_GESTURE} add column ${SqlConstant.TABLE_GESTURE_COLUMN_GESTURE_DESC} varchar(64)"
        db?.execSQL(sql)
    }

}